package com.kehutong.scheduled.worker;

import com.kehutong.common.DoveClient;
import com.kehutong.common.worker.Worker;
import org.coraframework.logger.Logger;
import org.coraframework.logger.LoggerFactory;
import org.coraframework.util.Ioc;

import java.time.LocalDateTime;

public class GenerateBillWorker implements Worker<GenerateBillWorker> {
	
	private static final Logger logger = LoggerFactory.getLogger(GenerateBillWorker.class);

    public GenerateBillWorker() {
        this.nextTime = LocalDateTime.now().plusMinutes(3);
        this.doveClient = Ioc.getInstance(DoveClient.class);
    }

    private LocalDateTime nextTime;
    private DoveClient doveClient;


    @Override
    public String getId() {
        return "generate-bill-worker";
    }

    @Override
    public void run() {
        this.doWork();
    }

    private void doWork() {
        try {
            doveClient.post("/payfees/charge/worker/generate/bill",(http)->{});
        }catch (Exception e){
            logger.error("generate bill errror:", e);
        }
    }

    @Override
    public boolean sendAble() {
        return LocalDateTime.now().isAfter(nextTime);
    }

    @Override
    public boolean isEffect() {
        return true;
    }

	@Override
	public LocalDateTime getHandTime() {
		return null;
	}
}
